﻿using JiebaNet.Segmenter;
using JiebaNet.Segmenter.PosSeg;
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Word = Microsoft.Office.Interop.Word;

namespace CTOOLS
{
   public class CWordFunc
    {
        object oMissing = System.Reflection.Missing.Value;
        object oMissingValue = System.Type.Missing;
        UnicodeCharList iUnicodeCharList = new UnicodeCharList();
        private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="wDoc"></param>
        /// <param name="wBDCFRange">标点符号重复</param>
        public bool Check_Word_Range(BackgroundWorker Worker,ref Word.Document wDoc, ref ArrayList wQLRange, ref ArrayList wSMRange)
        {
           
            bool rFlag = false;
            bool WHTable = false;//获取权利要求和说明书页眉是否包含Table


            Word.Range QLRange= null;//权利要求书
            Word.Range SMRange= null;//说明书
            Word.Range SMFTRange = null;//说明书附图
            string QLWTable = "", SMWTable="",SMFTWTable="";//页眉table
            //初始化ArrayList Range  begin
            wQLRange.Clear();
            wSMRange.Clear();
            //初始化ArrayList Range  end
            //权利要求书
            string[] QLFstr1 = { "。。", "；；","，；","；，","，。","。，","；。","。；" };
            string[] QLFstr2 = {  "等", "诸如", "约", "厚", "薄", "宽", "强", "高温", "很小", "很大", "如说明书", "如图" };//"或",
            string[] QLFstr3 = { "[\uFF10-\uFF19]" };
            string[] QLFstr4 = { "．" };
            string[] QLFstr5 = { @"([一-龥])\1" };//{@"([\u4e00-\u9fa5])\1" }; 
            //说明书
            string[] SMFstr0 = { "其特征在于"};
            string[] SMFstr1 = { "权利要求" };
            string[] SMFstr2 = { "实用新型", "发明"};
            string[] SMFstr3 = {"方法" };
           
            if (getQLSMPage(ref wDoc, ref QLRange, ref SMRange,ref SMFTRange, ref WHTable,ref QLWTable,ref SMWTable,ref SMFTWTable))//获取权利要求和说明书所在的节
            {
                if (QLRange != null)//存在权利要求书
                {
                    rFlag = true;
                    //FormProgressBar fp = new FormProgressBar(0, 6);//进度条
                    //fp.Show(fm);//设置父窗体
                    //fp.setSent(1, "检查【权利要求】标点符号重复");//设置进度条位置
                    Worker.ReportProgress(0, "正在检查【权利要求】标点符号重复......");
                    getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, QLFstr1, "【权利要求】标点符号重复","","QL");
                    Worker.ReportProgress(1, "正在检查【权利要求】敏感词汇......");//设置进度条位置
                    getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, QLFstr2, "【权利要求】敏感词汇", "","QL");
                    Worker.ReportProgress(2, "正在检查【权利要求】全角数字......");//设置进度条位置
                    getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, QLFstr3, "【权利要求】全角数字", "[\uFF10-\uFF19]", "QL");
                    Worker.ReportProgress(3, "正在检查【权利要求】全角符号(．)......");//设置进度条位置
                    getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, QLFstr4, "【权利要求】全角符号(．)","", "QL");
                    Worker.ReportProgress(4, "正在检查【权利要求】连续相同文字......");//设置进度条位置
                    getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, QLFstr5, "【权利要求】连续相同文字", "[一-龥]+", "QL");
                    Worker.ReportProgress(5, "正在检查【权利要求】权项检查......");//设置进度条位置
                    getFindQLYQDOCM(ref wDoc, ref QLRange, ref wQLRange, "【权利要求】权项检查", "QL",WHTable, QLWTable);
                   // fp.Close();
                    //getFindQLYQZYYY(ref wDoc, ref QLRange, ref wQLRange, "【权利要求】择一引用分析","QL");
                }
                if(SMRange != null)//存在说明书
                {
                    rFlag = true;
                    string DText = SMRange.Text;
                    //FormProgressBar fp = new FormProgressBar(0, 3);//进度条
                    //fp.Show(fm);//设置父窗体
                    //fp.setSent(1, "检查【说明书】禁止用语");//设置进度条位置
                    Worker.ReportProgress(1, "正在检查【说明书】禁止用语......");
                    //getFindDOCM(ref wDoc, ref SMRange, ref wSMRange, SMFstr1, "【说明书】禁止用语", "", "SM");
                    if (DText.IndexOf("其特征在于") >= 0)
                    {
                        JYResult iJYResultN = new JYResult();
                        iJYResultN.rNum = wSMRange.Count;
                        iJYResultN.sText = "【说明书】禁止用语:其特征在于";
                        iJYResultN.sType = "SM";
                        iJYResultN.sQStr = SMFstr0;
                        iJYResultN.pRange = SMRange;
                        wSMRange.Add(iJYResultN);
                    }
                    if (DText.IndexOf("权利要求") >= 0)
                    {
                        JYResult iJYResultN = new JYResult();
                        iJYResultN.rNum = wSMRange.Count;
                        iJYResultN.sText = "【说明书】禁止用语:权利要求";
                        iJYResultN.sType = "SM";
                        iJYResultN.sQStr = SMFstr1;
                        iJYResultN.pRange = SMRange;
                        wSMRange.Add(iJYResultN);
                    }
                    //判断说明书中的“实用新型”和“发明”同时出现
                    Worker.ReportProgress(2, "正在检查【说明书】实用新型和发明......");//设置进度条位置
                    if (DText.IndexOf("实用新型")>=0 && DText.IndexOf("发明") >= 0)
                    {
                        //getFindDOCM(ref wDoc, ref SMRange, ref wSMRange, SMFstr2, "【说明书】中同时出现[实用新型]和[发明]", "", "SM");
                        JYResult iJYResultN = new JYResult();
                        iJYResultN.rNum = wSMRange.Count;
                        iJYResultN.sText = "【说明书】中同时出现[实用新型]和[发明]";
                        iJYResultN.sType = "SM";
                        iJYResultN.sQStr = SMFstr2;
                        iJYResultN.pRange = SMRange;
                        wSMRange.Add(iJYResultN);
                    }
                    //判断说明书中“实用新型”和权利要求书中“方法”出现的检查
                    Worker.ReportProgress(3, "正在检查【说明书】实用新型和方法......");//设置进度条位置
                    if (DText.IndexOf("实用新型") >= 0 && QLRange != null)
                    {
                        //getFindDOCM(ref wDoc, ref QLRange, ref wQLRange, SMFstr3, "【说明书】出现[实用新型]和权利要求出现[方法]", "", "QL");
                        JYResult iJYResultN = new JYResult();
                        iJYResultN.rNum = wQLRange.Count;
                        iJYResultN.sText = "【说明书】出现[实用新型]和权利要求出现[方法]";
                        iJYResultN.sType = "QL";
                        iJYResultN.sQStr = SMFstr3;
                        iJYResultN.pRange = QLRange;
                        wQLRange.Add(iJYResultN);
                    }
                    if (SMFTRange != null)
                    {
                        Worker.ReportProgress(4, "正在检查【说明书】中的图号......");//设置进度条位置
                        string DFTText = SMFTRange.Text;
                        string[] smftA=find_str(@"图[0-9a-zA-Z]+", DFTText);//获取说明书附图中的附图号
                        ArrayList sLmftA = new ArrayList(smftA);
                        ArrayList sLmftALL = new ArrayList();
                        ArrayList sLmftAZM = new ArrayList(new string[] {"a","b","c","d","e","g","h","k","l","m","n","o","q","r","s","u","v","w","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"});
                        
                        //“-”“~”“～”“至”“到”
                        //string[] sss=find_str(@"图[0-9a-zA-Z]+", DText);
                        List <string> sFindA = new List<string>();
                         List<int> lFindA = new List<int>();
                        string[] aFlagA = { "-", "~", "～", "至", "到" };
                        string sValue = "", sValue1 = "";
                        string sB = "", sE = "";
                        string sBZ = "", sEZ = "";
                        int iB = 0, iE = 0;
                        int iBZ = 0, iEZ = 0;
                        bool bSFlag = false, bf=false;
                        find_str(@"图[0-9a-zA-Z]+", DText, ref sFindA, ref lFindA);
                        for (int i = 0; i < (sFindA.Count - 1); i++)
                        {
                            bSFlag = false;
                            sValue = DText.Substring(lFindA[i] + sFindA[i + 1].Length, lFindA[i + 1] - lFindA[i] - sFindA[i + 1].Length);

                            if (!string.IsNullOrEmpty(sValue))
                            {
                                sValue1 = sValue.Trim();
                                foreach (string sv in aFlagA)
                                {
                                    if (sv == sValue1)
                                    {
                                        bSFlag = true;
                                        break;
                                    }
                                }
                            }
                            if (bSFlag)
                            {
                                if(sFindA[i] == sFindA[i + 1])
                                {
                                    if (sLmftA.Contains(sFindA[i]) == false && sLmftALL.Contains(sFindA[i] + sValue+ sFindA[i+1]) == false)
                                    {
                                        sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                    }
                                }
                                else
                                {
                                    iB = 0;
                                    iE = 0;
                                    sB = PubFunClass.GetStrNum(sFindA[i]);
                                    sE = PubFunClass.GetStrNum(sFindA[i + 1]);
                                    if(PubFunClass.StrToNumeric(sB,ref iB) && PubFunClass.StrToNumeric(sE, ref iE))
                                    {
                                        //图号中数字的处理
                                        if (iB > iE)
                                        {
                                            if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                            {
                                                sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                            }
                                        }
                                        else
                                        {
                                            //获取图号字母 大于1位字母的视为图号 在范围值中不正确
                                            sBZ = sFindA[i].Substring(("图" + iB.ToString()).Length);
                                            sEZ = sFindA[i + 1].Substring(("图" + iE.ToString()).Length);
                                            if(sBZ.Length>1 || sEZ.Length > 1)
                                            {
                                                if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                                {
                                                    sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                                }
                                            }
                                            else if ((sBZ.Length == 0 && sEZ.Length >=1) || (sBZ.Length >=1 && sEZ.Length == 0))
                                            {
                                                if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                                {
                                                    sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                                }
                                            }
                                            else if(sBZ.Length ==0 && sEZ.Length==0)
                                            {
                                                for (int j = iB; j <= iE; j++)//循环数字
                                                {
                                                    if (sLmftA.Contains("图" + j.ToString()) == false)
                                                    {
                                                        if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                                        {
                                                            sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            else//字母一位的处理
                                            {
                                                bf = false;
                                                //获取字母位置
                                                iBZ = sLmftAZM.IndexOf(sBZ);
                                                iEZ = sLmftAZM.IndexOf(sEZ);
                                                for(int j= iB;j<= iE; j++)//循环数字
                                                {
                                                    for(int k= iBZ;k< sLmftAZM.Count; k++)//遍历字母
                                                    {                                                       
                                                        if(sLmftA.Contains("图" + j.ToString() + sLmftAZM[k]) == false)
                                                        {
                                                            if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                                            {
                                                                sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                                            }
                                                            bf = true;
                                                            break;
                                                        }
                                                        if (("图" + j.ToString() + sLmftAZM[k]) == sFindA[i + 1])
                                                        {
                                                            bf = true;
                                                            break;
                                                        }
                                                      }
                                                      if (bf) break;
                                                      iBZ = 0;
                                                    }
                                                }
                                            }
                                        }
                                        else//如果转换int失败，则显示在错误图号列表中
                                        {
                                            if (sLmftALL.Contains(sFindA[i] + sValue + sFindA[i + 1]) == false)
                                            {
                                                sLmftALL.Add(sFindA[i] + sValue + sFindA[i + 1]);
                                            }
                                        }                                                                       
                                    }
                                i = i + 1;                                
                            }
                            else
                            {
                                if (sLmftA.Contains(sFindA[i]) == false && sLmftALL.Contains(sFindA[i])==false)
                                {
                                    sLmftALL.Add(sFindA[i]);
                                }
                            }
                        }


                        List<string> fsA = new List<string>((string[])sLmftALL.ToArray(typeof(string)));
                        fsA = fsA.OrderByDescending(s => s.Length).ToList();//倒叙排序
                        foreach (string sl in fsA)
                        {
                            string[] smFT = { sl };
                            JYResult iJYResultN = new JYResult();
                            iJYResultN.rNum = wSMRange.Count;
                            iJYResultN.sText = "【说明书附图检查】-["+ sl + "]图号引用存在问题";
                            iJYResultN.sType = "SM";
                            iJYResultN.sQStr = smFT;
                            iJYResultN.pRange = SMRange;
                            wSMRange.Add(iJYResultN);
                        }


                    }
                }
            }
            return rFlag;
        }


        public void getFindDOCM(ref Word.Document wDoc,Word.Range DRange,string[] Fstr,string sregex)
        {
            int iCount = 0,irow=0;
            int sS = 0, eS = 0;
            int sSC = 0;

            bool wFindFlag = false;
            if (DRange.Paragraphs != null && DRange.Paragraphs.Count > 0)
            {

                iCount = DRange.Paragraphs.Count;
                Word.Range SRange;
                Word.Range SRangeSelect=null;
                int s = DRange.Start, e = DRange.End;
                string DText = DRange.Text;
                foreach (string fS in Fstr)
                {
                    irow = 0;
                    if (string.IsNullOrEmpty(sregex))
                    {
                        if (!(DText.IndexOf(fS) >= 0)) continue;
                    }
                    else
                    {
                        if (find_count(sregex, DText) == 0) continue;
                    }


                    SRange = wDoc.Range(s, e);
                   // Word.WdColorIndex wc = SRange.HighlightColorIndex;// = Word.WdColorIndex.wdYellow;
                    SRange.Find.ClearFormatting();
                    SRange.Find.ClearHitHighlight();
                    SRange.Find.Forward = true;
                    //SRange.Find.Highlight = 1;
                    SRange.Find.MatchWildcards = true;
                    SRange.Find.Text = fS;
                    do
                    {
                        irow++;
                        wFindFlag = SRange.Find.Execute(ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue);
                        if (wFindFlag)//(wDoc.Application.Selection.Find.Found)
                        {
                            sS = SRange.Start;
                            eS = SRange.End;
                            if (sS <= e)
                            {
                                if (irow == 1)
                                {
                                    if (sSC>sS || sSC==0)
                                    {
                                        sSC = sS;
                                        SRangeSelect = wDoc.Range(sS, eS);
                                        SRangeSelect.HighlightColorIndex = Word.WdColorIndex.wdYellow;
                                    }
                                    else
                                    {
                                        wDoc.Range(sS, eS).HighlightColorIndex = Word.WdColorIndex.wdYellow;
                                    } 
                                }
                                else
                                {
                                    wDoc.Range(sS, eS).HighlightColorIndex = Word.WdColorIndex.wdYellow;
                                }
                                
                                if (eS > e) break;
                            }
                            else
                            {
                                break;
                            }

                        }
                        else
                        {
                            break;
                        }
                    } while (true);
                }
                if (irow>0) SRangeSelect.Select();
            }
        }

        private void getFindDOCM(ref Word.Document wDoc, ref Word.Range DRange, ref ArrayList wRange, string[] Fstr,string stypeText,string sregex, string sType)
        {

            int iCount = 0,iacount = 0;
            int sS = 0,eS = 0;
 
            bool wFindFlag = false;
            if (DRange.Paragraphs != null && DRange.Paragraphs.Count > 0)
            {
                
                iCount = DRange.Paragraphs.Count;
                Word.Range SRange;
                int s= DRange.Start, e= DRange.End;
                string DText=DRange.Text;
                foreach (string fS in Fstr)
                {
                    if (string.IsNullOrEmpty(sregex))
                    {
                        if (!(DText.IndexOf(fS) >= 0)) continue;
                    }
                    else
                    {
                        if (find_count(sregex, DText) == 0) continue;
                    }


                    SRange =wDoc.Range(s, e);

                    SRange.Find.ClearFormatting();
                    SRange.Find.Forward = true;
                    SRange.Find.MatchWildcards = true;
                    SRange.Find.Text = fS;
                    do
                    {
                        wFindFlag = SRange.Find.Execute(ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue, ref oMissingValue,
                                 ref oMissingValue);
                        if (wFindFlag)//(wDoc.Application.Selection.Find.Found)
                        {
                            sS=SRange.Start;
                            eS=SRange.End;
                            if (sS <= e)
                            {
                                iacount = wRange.Count;
                                JYResult iJYResult = new JYResult();
                                iJYResult.rNum = iacount;
                                iJYResult.sText = stypeText + "：[" + SRange.Text + "]";//stypeText + "：" + fS + "  [" + SRange.Text + "]";
                                iJYResult.sType = sType;
                                iJYResult.pRange = wDoc.Range(sS, eS);
                                iacount = iacount + 1;
                                wRange.Add(iJYResult);
                                if (eS > e) break;
                            }else
                            {
                                break;
                            }
                            
                            //ucText = pRanges.Text;
                        }
                        else
                        {
                            break;
                        }
                    } while (true);
                }
                //foreach (string fS in Fstr)
                //{

                //    DRange.Select();
                //    wDoc.Application.Selection.Find.ClearFormatting();
                //    wDoc.Application.Selection.Find.Forward = true;
                //    wDoc.Application.Selection.Find.Text = fS;
                //    do
                //    {
                //        wFindFlag = wDoc.Application.Selection.Find.Execute(ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue, ref oMissingValue,
                //                 ref oMissingValue);
                //        if (wFindFlag)//(wDoc.Application.Selection.Find.Found)
                //        {
                //            iacount = wRange.Count;
                //            JYResult iJYResult = new JYResult();
                //            iJYResult.rNum = iacount;
                //            iJYResult.sText = stypeText + "：" + fS + "  [" + fS + "]";
                //            iJYResult.sType = sType;
                //            iJYResult.pRange = wDoc.Range(wDoc.Application.Selection.Range.Start, wDoc.Application.Selection.Range.End);
                //            iacount = iacount + 1;
                //            wRange.Add(iJYResult);
                //            //ucText = pRanges.Text;
                //        }
                //        else
                //        {
                //            break;
                //        }
                //    } while (true);
                //}

            }
        }



        private void getFindQLYQDOCM(ref Word.Document wDoc, ref Word.Range DRange, ref ArrayList wRange,string stypeText, string sType,bool WHTable,string WTable)
        {
            if (DRange.Paragraphs != null && DRange.Paragraphs.Count > 0)
            {
                string DText = DRange.Text;
                int[] dxql=null;
                int iCount = 0, sLen = 0, qlNum = 0, Num = 1, nullNum = -10000, qxNum = 0 ;
                string str1 = "",str2="";//每行内容
                string strHW ="";//行尾符号
                string sqxnr = "";//权项对应的内容
                string strXH = "",strErr="", strBD="";
                ArrayList xhsz = new ArrayList();//项号数组
                ArrayList qxnr = new ArrayList();//权项对应的内容数组
                List<string> qxnrlist = new List<string>(); //权项对应的内容
                ArrayList dxqlsz = new ArrayList();//多项权利要求项号数组
               

                bool flagQJ = false;
                Word.Range QXRange; //权项对应的word内容

                 iCount = DRange.Paragraphs.Count;
                for(int i=1;i<= iCount; i++)
                {
                    strErr = "";
                    //
                    dxql = null;

                    //获取权利要求序号
                    str1 =DRange.Paragraphs[i].Range.Text;
                    if (WHTable == true)
                    {
                        if (str1 == WTable) continue;//判断行是否为低版本模板页眉
                    }


                    str1 = str1.Trim();
                    if (string.IsNullOrEmpty(str1)) continue;
                    if (!Regex.IsMatch(str1, ".*[\\u4e00-\\u9faf].*")) continue;//判断行是否包含汉字

                    sqxnr = sqxnr + str1+ "\r" ;// 权项对应的内容
                    //QXRange = DRange.Paragraphs[i].Range;//项号对应的WORD句子

                    if (str1.Length < 10)
                    { sLen = str1.Length; }
                    else
                    { sLen = 10; }

                    strXH = getQLYQXHDOCM(str1, ref flagQJ);//获取项号
                    //获取行结尾最后一位
                    if (str1.Length > 1)
                    { strHW = str1.Substring(str1.Length - 1, 1);}
                    else
                    { strHW = str1;}
                   

                    if (string.IsNullOrEmpty(strXH))
                    {
                        strErr = "项号缺失";
                        qxNum = nullNum--;
                        xhsz.Add(qxNum);//放入项号数组
                    }
                    else if (flagQJ)
                    {
                        strErr = "项号包含全角数字";
                        qxNum = Convert.ToInt32(strXH);
                        xhsz.Add(qxNum);//放入项号数组
                    }
                    else
                    {
                        qxNum = Convert.ToInt32(strXH);
                        xhsz.Add(qxNum);//放入项号数组
                        if (str1.Length> strXH.Length)
                        {
                            strBD=str1.Substring(strXH.Length, 1);//项号后的标点符号
                            if (strBD.Equals(".") == false)
                            {
                                strErr = "项号数字后的标点不符合要求";
                            }
                            //else
                            //{
                            //    qxnrlist.Add(sqxnr);
                            //    sqxnr = "";
                            //    continue;
                            //}
                        }
                        else
                        {
                            strErr = "项号缺少(.)";
                        }
                    }
                    if (!string.IsNullOrEmpty(strErr))
                    {
                        JYResult iJYResult = new JYResult();
                        iJYResult.rNum = wRange.Count;
                        iJYResult.sText = stypeText + "：" + strErr + "[" + str1.Substring(0, sLen - 1) + ".....]";
                        iJYResult.sType = sType;
                        iJYResult.pRange = DRange.Paragraphs[i].Range;
                        wRange.Add(iJYResult);
                    }
                   
                    //判断行尾是否为句号
                    if (strHW.Equals("。")==false)
                    {
                        qlNum = i + 1;
                        //判断下一行，是否为权项行，如果是，则输出该行缺少句号结尾，如果不是，则查找下一行行尾是否有句号，如果有，则结束该行检索，到下一行，如果没有则继续找
                        if (sFindQLYQ(iCount, ref qlNum, ref wDoc, ref DRange, ref wRange, stypeText, sType)==false)
                        {
                            //获取权项word文本
                            for (int k = (i + 1); k <= qlNum; k++)
                            {
                                str2 = DRange.Paragraphs[k].Range.Text;
                                str2 = str2.Trim();
                                if (string.IsNullOrEmpty(str2)) continue;
                                sqxnr = sqxnr + str2 + "\r";// 权项对应的内容
                            }
                            //
                            if ((i + 1) < qlNum)
                            {
                                QXRange = wDoc.Range(DRange.Paragraphs[i].Range.Start, DRange.Paragraphs[qlNum].Range.End);
                            }
                            else
                            {
                                QXRange = DRange.Paragraphs[i].Range;//项号对应的WORD句子
                            }
                            //将权项内容和权项写入数组类
                            JYResult iJYResult2 = new JYResult();
                            iJYResult2.sType = is_duoxiang(qxNum > 0 ? qxNum : xhsz.Count, ref dxql, sqxnr).ToString();//是否为引用多项权利
                            iJYResult2.iOther = dxql;//将引用的多项权利要求项号放入数组
                            iJYResult2.sQXDQ = is_independent_claim(sqxnr).ToString();//是否为独立权利要求
                            iJYResult2.sText = sqxnr;//权项word内容
                            iJYResult2.rNum = qxNum;//权项号
                            iJYResult2.pRange = QXRange;
                            qxnr.Add(iJYResult2);
                            qxnrlist.Add(sqxnr);
                          //  DText = DText + "▇" + sqxnr;
                            if (iJYResult2.sType=="True") dxqlsz.Add(qxNum);//多项权利要求项号数组
                            sqxnr = "";

                            i = qlNum;
                            continue;
                        }
                        else
                        {
                            //获取权项word文本
                            for (int k = (i + 1); k < qlNum; k++)
                            {
                                str2 = DRange.Paragraphs[k].Range.Text;
                                str2 = str2.Trim();
                                if (string.IsNullOrEmpty(str2)) continue;
                                sqxnr = sqxnr + str2 + "\r";// 权项对应的内容
                            }
                            //
                            if ((i + 1) < qlNum)
                            {
                                QXRange = wDoc.Range(DRange.Paragraphs[i].Range.Start, DRange.Paragraphs[qlNum - 1].Range.End);
                            }
                            else
                            {
                                QXRange = DRange.Paragraphs[i].Range;//项号对应的WORD句子
                            }
                            //记录检索结果
                            i =qlNum - 1;
                            JYResult iJYResult1 = new JYResult();
                            iJYResult1.rNum = wRange.Count;
                            iJYResult1.sText = stypeText + "：权项结束缺少(。)[" + str1.Substring(0, sLen - 1) + ".....]";
                            iJYResult1.sType = sType;
                            iJYResult1.pRange = DRange.Paragraphs[i].Range;
                            wRange.Add(iJYResult1);

                            //将权项内容和权项写入数组类
                            JYResult iJYResult2 = new JYResult();
                            iJYResult2.sType = is_duoxiang(qxNum > 0 ? qxNum : xhsz.Count,ref dxql, sqxnr).ToString();//是否为引用多项权利
                            iJYResult2.iOther=dxql;//将引用的多项权利要求项号放入数组
                            iJYResult2.sQXDQ = is_independent_claim(sqxnr).ToString();//是否为独立权利要求
                            iJYResult2.sText = sqxnr;//权项word内容
                            iJYResult2.rNum = qxNum;//权项号
                            iJYResult2.pRange = QXRange;
                            qxnr.Add(iJYResult2);
                            qxnrlist.Add(sqxnr);
                          //  DText = DText + "▇" + sqxnr;
                            if (iJYResult2.sType == "True") dxqlsz.Add(qxNum);//多项权利要求项号数组
                            sqxnr = "";
                        }
                    }
                    else
                    { 
                        JYResult iJYResult2 = new JYResult();
                        iJYResult2.sType = is_duoxiang(qxNum > 0 ? qxNum : xhsz.Count, ref dxql, sqxnr).ToString();//是否为引用多项权利
                        iJYResult2.iOther = dxql;//将引用的多项权利要求项号放入数组
                        iJYResult2.sQXDQ = is_independent_claim(sqxnr).ToString();//是否为独立权利要求
                        iJYResult2.sText = sqxnr;//权项word内容
                        iJYResult2.rNum = qxNum;//权项号
                        iJYResult2.pRange = DRange.Paragraphs[i].Range;//项号对应的WORD句子;
                        qxnr.Add(iJYResult2);
                        qxnrlist.Add(sqxnr);
                       // DText = DText+"▇" + sqxnr;
                        if (iJYResult2.sType == "True") dxqlsz.Add(qxNum);//多项权利要求项号数组
                        sqxnr = "";
                    }
                }
                //检查权项是否按照数字顺序编号
                foreach(int n in xhsz)
                {
                    if (Num != n && n > -10000)
                    {
                        JYResult iJYResultN = new JYResult();
                        iJYResultN.rNum = wRange.Count;
                        iJYResultN.sText = stypeText + "：权利要求序号不连续]";
                        iJYResultN.sType = sType;
                        iJYResultN.pRange = DRange.Paragraphs[1].Range;
                        wRange.Add(iJYResultN);
                        break;
                    }
                    else
                    {
                        Num++;
                    }
                }
                //特征分析
                ArrayList qxAL = GetTeZheng(qxnrlist);
                int qxlistNum = 0;
                string ms = "";
                string sstr = "";
                string qsStr = "";
                //int mL = 0;
                //string mOneC = "";
                bool bqxtzcz = false;//判断权项特征是否在所述前存在
                List<string> qstz = new List<string>();//获取所述前的特征
                List<string> qssstz = new List<string>();//获取所述特征
                //List<string> qxtz = new List<string>(); //当前权项特征数组

                //检查是否存在多引多|非择一
                foreach (JYResult nJYResultN in qxnr)
                {
                    if (nJYResultN.sType == "True")
                    {
                        if (nJYResultN.sQXDQ == "False")
                        {
                            if ((!ismatch("任何一|之一|任意一项|任一|或|任意|任意一", nJYResultN.sText) | ismatch("多项", nJYResultN.sText)) | (!ismatch("任何一|之一|任意一项|任一|任意|任意一", nJYResultN.sText) & ismatch(@"权利要求[^，；,]*\d+和/或\d+|权利要求[^，；,]*\d+或/和\d+", nJYResultN.sText)))
                            {
                                JYResult iJYResultN = new JYResult();
                                iJYResultN.rNum = wRange.Count;
                                iJYResultN.sText = stypeText + "：权利要求" + nJYResultN.rNum.ToString() + "非择一。]";
                                iJYResultN.sType = sType;
                                iJYResultN.pRange = nJYResultN.pRange;
                                wRange.Add(iJYResultN);
                                break;
                            }
                        }

                        foreach (int di in nJYResultN.iOther)
                        {
                            if (dxqlsz.Contains(di))
                            {
                                JYResult iJYResultN = new JYResult();
                                iJYResultN.rNum = wRange.Count;
                                iJYResultN.sText = stypeText + "：权利要求" + nJYResultN.rNum.ToString() + "存在多引多项。]";
                                iJYResultN.sType = sType;
                                iJYResultN.pRange = nJYResultN.pRange;
                                wRange.Add(iJYResultN);
                                break;
                            }
                        }
                    }

                    if (nJYResultN.iOther != null)
                    {
                        if (nJYResultN.iOther.Contains(nJYResultN.rNum) && nJYResultN.iOther.Max() >= nJYResultN.rNum)
                        {
                            JYResult iJYResultN = new JYResult();
                            iJYResultN.rNum = wRange.Count;
                            iJYResultN.sText = stypeText + "：权利要求" + nJYResultN.rNum.ToString() + "引用自身或者在后的权利要求。]";
                            iJYResultN.sType = sType;
                            iJYResultN.pRange = nJYResultN.pRange;
                            wRange.Add(iJYResultN);
                        }
                         
                    }

                    //“所述”没有引用基础分许
                    if (qxAL != null)
                    {
                        List<string> qxtz = (List<string>)qxAL[qxlistNum];//当前权项特征数组
                        //分析所述
                        MatchCollection matchs4 = Regex.Matches(nJYResultN.sText, "所述的|前述的|上述的|所述|上述|前述|(?<!应)该");
                        for(int m=0;m< matchs4.Count; m++)
                        {
                            ms = "";
                            bqxtzcz = false;
                            qstz.Clear();
                            qssstz.Clear();
                            if (nJYResultN.sQXDQ == "True")//是独权
                            {
                                qsStr = nJYResultN.sText.Substring(0, matchs4[m].Index);//前述字符串
                                foreach (string tz in qxtz)//获取前述特征
                                {
                                    if (qsStr.IndexOf(tz) >= 0)
                                    {
                                        qstz.Add(tz);
                                    }
                                }
                                if ((m+1)>= matchs4.Count)
                                {
                                    if (matchs4[m].Index + matchs4[m].Value.Length== nJYResultN.sText.Length)
                                    {
                                        sstr = "";
                                    }
                                    else
                                    {
                                        sstr = nJYResultN.sText.Substring(matchs4[m].Index + matchs4[m].Value.Length, nJYResultN.sText.Length - matchs4[m].Index - matchs4[m].Value.Length);//当前所述字符串
                                    }  
                                }
                                else
                                {
                                    sstr = nJYResultN.sText.Substring(matchs4[m].Index + matchs4[m].Value.Length, matchs4[m+1].Index - matchs4[m].Index - matchs4[m].Value.Length);
                                }

                                foreach (string tz in qxtz)//获取所述特征
                                {
                                    if (sstr.IndexOf(tz) == 0)
                                    {
                                        qssstz.Add(tz);
                                    }
                                }
                                qssstz = qssstz.OrderByDescending(s => s.Length).ToList();//倒叙排序
                                qstz = qstz.OrderByDescending(s => s.Length).ToList();//倒叙排序
                                foreach (string qst in qstz)//判断是否在所述前有引用基础
                                {
                                    if (qssstz.Contains(qst))
                                    {
                                        bqxtzcz = true;
                                        break;
                                    }
                                }

                                if (bqxtzcz == false && qssstz.Count>0)
                                {
                                    string[] QLFstr1 = { qssstz[0] };
                                    //Word.Range pR = nJYResultN.pRange;
                                    //getFindDOCM(ref wDoc, ref pR, ref wRange, QLFstr1, stypeText + "[权利要求" + nJYResultN.rNum.ToString()+ "]所述特征缺乏引用基础", "", "QL");
                                    JYResult iJYResultN = new JYResult();
                                    iJYResultN.rNum = wRange.Count;
                                    iJYResultN.sText = stypeText + "：权利要求" + nJYResultN.rNum.ToString() + "所述特征[" + qssstz[0] + "]缺乏引用基础。]";
                                    iJYResultN.sType = sType;
                                    iJYResultN.sQStr = QLFstr1;
                                    iJYResultN.pRange = nJYResultN.pRange;
                                    wRange.Add(iJYResultN);
                                }

                            }else//从权
                            {
                                foreach(int qz in nJYResultN.iOther)
                                {
                                    foreach (string tz in ((List<string>)qxAL[qz - 1]))//获取前述特征
                                    {
                                        qstz.Add(tz);
                                    }
                                }
                                
                                if ((m + 1) >= matchs4.Count)
                                {
                                    if (matchs4[m].Index + matchs4[m].Value.Length == nJYResultN.sText.Length)
                                    {
                                        sstr = "";
                                    }
                                    else
                                    {
                                        sstr = nJYResultN.sText.Substring(matchs4[m].Index + matchs4[m].Value.Length, nJYResultN.sText.Length - matchs4[m].Index - matchs4[m].Value.Length);//当前所述字符串
                                    }
                                }
                                else
                                {
                                    sstr = nJYResultN.sText.Substring(matchs4[m].Index + matchs4[m].Value.Length, matchs4[m + 1].Index - matchs4[m].Index - matchs4[m].Value.Length);
                                }

                                foreach (string tz in qxtz)//获取所述特征
                                {
                                    if (sstr.IndexOf(tz) == 0)
                                    {
                                        qssstz.Add(tz);
                                    }
                                }
                                qssstz = qssstz.OrderByDescending(s => s.Length).ToList();//倒叙排序
                                qstz = qstz.OrderByDescending(s => s.Length).ToList();//倒叙排序
                                foreach (string qst in qstz)//判断是否在所述前有引用基础
                                {
                                    if (qssstz.Contains(qst))
                                    {
                                        bqxtzcz = true;
                                        break;
                                    }
                                }

                                if (bqxtzcz == false && qssstz.Count > 0)
                                {
                                    string[] QLFstr1 = { qssstz[0] };
                                    //Word.Range pR = nJYResultN.pRange;
                                    //getFindDOCM(ref wDoc, ref pR, ref wRange, QLFstr1, stypeText + "[权利要求" + nJYResultN.rNum.ToString() + "]所述特征缺乏引用基础", "", "QL");
                                    JYResult iJYResultN = new JYResult();
                                    iJYResultN.rNum = wRange.Count;
                                    iJYResultN.sText = stypeText + "：权利要求" + nJYResultN.rNum.ToString() + "所述特征[" + qssstz[0] + "]缺乏引用基础。]";
                                    iJYResultN.sType = sType;
                                    iJYResultN.sQStr = QLFstr1;
                                    iJYResultN.pRange = nJYResultN.pRange;
                                    wRange.Add(iJYResultN);
                                }
                            }
                        }
                    }
                    //不简要分析
                    if (nJYResultN.sQXDQ == "True")//是独权
                    { }
                    else//从权
                    {
                        bqxtzcz = false;
                        string sqx = "";
                        if (ismatch("其特征在于[,，:：]", nJYResultN.sText))
                        {
                            int[] numArrayTZ = find_pos("其特征在于[,，:：]", nJYResultN.sText);
                            if (numArrayTZ.Length > 0)
                            {
                                string TZHstr = nJYResultN.sText.Substring(numArrayTZ[0] + 6);//获取 其特征在于 后的内容
                                foreach (int qz in nJYResultN.iOther)
                                {
                                    JYResult jyr=(JYResult)qxnr[qz - 1];
                                    sqx = sqx + "\n" + jyr.sText;
                                }
                                string[] strArrayTZH = find_str(@"[^,，;；。\n]+", TZHstr);//其特征在于 后的内容按照特定字符分组
                                foreach (string strTZH in strArrayTZH)
                                {
                                    string strRTZH = Regex.Replace(strTZH, "所述的|所述|该|上述的|上述|前述的|前述", "");
                                    if ((find_count0(strTZH, sqx) < 1) && (find_count0(strRTZH, sqx) < 1))
                                    {
                                        bqxtzcz = false;
                                        break;
                                    }
                                    if ((find_count0(strTZH, DText) > 1) && (find_count0(strRTZH, DText) > 1))
                                    {
                                        bqxtzcz = true;
                                    }
                                }

                                if (bqxtzcz)
                                {
                                    JYResult iJYResultN = new JYResult();
                                    iJYResultN.rNum = wRange.Count;
                                    iJYResultN.sText = stypeText + "：简要分析-权利要求" + nJYResultN.rNum.ToString() + "不简要。]";
                                    iJYResultN.sType = sType;
                                    iJYResultN.pRange = nJYResultN.pRange;
                                    wRange.Add(iJYResultN);
                                }
                            }
                        }
                        else if (ismatch("[,，:：]", nJYResultN.sText))
                        {
                            int[] numArrayTZ = find_pos("[,，:：]", nJYResultN.sText);
                            if (numArrayTZ.Length > 0)
                            {
                                string TZHstr = nJYResultN.sText.Substring(numArrayTZ[0]);//获取内容
                                foreach (int qz in nJYResultN.iOther)
                                {
                                    JYResult jyr = (JYResult)qxnr[qz - 1];
                                    sqx = sqx + "\n" + jyr.sText;
                                }
                                string[] strArrayTZH = find_str(@"[^,，;；。\n]+", TZHstr);//其特征在于 后的内容按照特定字符分组
                                foreach (string strTZH in strArrayTZH)
                                {
                                    string strRTZH = Regex.Replace(strTZH, "所述的|所述|该|上述的|上述|前述的|前述", "");
                                    if ((find_count0(strTZH, sqx) < 1) && (find_count0(strRTZH, sqx) < 1))
                                    {
                                        bqxtzcz = false;
                                        break;
                                    }
                                    if ((find_count0(strTZH, DText) > 1) && (find_count0(strRTZH, DText) > 1))
                                    {
                                        bqxtzcz = true;
                                    }
                                }

                                if (bqxtzcz)
                                {
                                    JYResult iJYResultN = new JYResult();
                                    iJYResultN.rNum = wRange.Count;
                                    iJYResultN.sText = stypeText + "：简要分析-权利要求" + nJYResultN.rNum.ToString() + "不简要。]";
                                    iJYResultN.sType = sType;
                                    iJYResultN.pRange = nJYResultN.pRange;
                                    wRange.Add(iJYResultN);
                                }
                            }
                         }
                    }
                        

                qxlistNum++;
                }

               

                //特征附图标记分析
                if (qxAL != null)
                {
                    int qxjs = 0;
                    string strArraySZ = "";
                    string strSTZSZ = "", strtemp="";
                    string strQL = DText;
                    List<string> listT = new List<string>();

                    List<string> listSTZSZ = new List<string>();//特征文字数组
                    List<int> listITZSZ = new List<int>();//特征对应的权项数组
                    List<string> listYJSSZ = new List<string>();//特征已经检索对比
                    List<string> listTEMP = new List<string>();//特征临时数组
                    List<string> listTEMPJS = new List<string>();//特征临时计数数组
                    List<string> listTEMPKHJS = new List<string>();//特征临时计数数组
                    foreach (List<string> strAL in qxAL)
                    {
                        foreach (string strTZ in strAL)
                        {
                            if (IsNumber(strTZ)) continue;
                            if (!listSTZSZ.Contains(strTZ))
                            {
                                listSTZSZ.Add(strTZ);
                                listITZSZ.Add(qxjs);
                            }
                        }
                        qxjs++;
                    }
                    
                    for (int i = 0; i < listSTZSZ.Count; i++)
                    {
                        strSTZSZ = listSTZSZ[i];
                        if (!listYJSSZ.Contains(strSTZSZ))
                        {
                            listTEMP.Clear();
                            for (int j = i+1; j < listSTZSZ.Count; j++)
                            {
                                strtemp = listSTZSZ[j];
                                if (strtemp.IndexOf(strSTZSZ)>=0 && strtemp.Length> strSTZSZ.Length)
                                {//
                                    listTEMP.Add(strtemp);
                                }//
                            }

                            listTEMP.Add(strSTZSZ);
                            // listTEMP.OrderBy(s => s.Length).ToArray();
                            listTEMP=listTEMP.OrderByDescending(s => s.Length).ToList();

                            foreach (string strT in listTEMP)
                            {
                                listYJSSZ.Add(strT);
                                listT.Clear();
                                string[] strArrayList = find_str(strT + @"[\(\（][^\(\)\（\）]+[\)\）]", strQL);
                                strQL = Regex.Replace(strQL, strT + @"[\(\（][^\(\)\（\）]+[\)\）]", "");
                                foreach (string strTemp in strArrayList)
                                {
                                    if (!listT.Contains(strTemp))
                                    {
                                        listT.Add(strTemp);
                                        if (!listTEMPKHJS.Contains(strTemp)) listTEMPKHJS.Add(strTemp); //存放所有刻号特征，用于刻号相同，特征不同比较
                                    }
                                }
                                //特征中带数字
                                if (strT != null && Regex.IsMatch(strT, "[0-9]+$"))
                                {
                                    strArraySZ = Regex.Replace(strT, @"[0-9]", "");
                                }else
                                {
                                    strArraySZ = strT;
                                }

                                string[] strlistTSZ = find_str(strArraySZ + @"[0-9]+", strQL);
                                strQL = Regex.Replace(strQL, strArraySZ + @"[0-9]+", "");
                                //listTEMPJS.Clear();
                                foreach (string strTSZ in strlistTSZ)
                                {
                                    if (!listT.Contains(strTSZ))
                                    {
                                        listT.Add(strTSZ);
                                        if (!listTEMPJS.Contains(strTSZ)) listTEMPJS.Add(strTSZ);//存放所有数组特征，用于数字相同，特征不同比较
                                        listYJSSZ.Add(strTSZ);
                                    }
                                }

                                qxjs = listSTZSZ.IndexOf(strT);
                                qxjs=listITZSZ[qxjs];


                                if (listT.Count > 1)
                                {
                                    //getFindDOCM(ref wDoc, ref DRange, ref wRange, listT.ToArray(), stypeText + "：相同特征采用不同附图标记[" + string.Join(",", listT.ToArray()) + "]", "", "QL");
                                    JYResult iJYResultN = new JYResult();
                                    iJYResultN.rNum = wRange.Count;
                                    iJYResultN.sText = stypeText + "：相同特征采用不同附图标记[" + string.Join(",", listT.ToArray()) + "]";
                                    iJYResultN.sType = sType;
                                    iJYResultN.sQStr = listT.ToArray();
                                    iJYResultN.pRange = DRange;
                                    wRange.Add(iJYResultN);
                                }
                            }
                        }
                    }

                    //判断带刻号的特征是否存在相同号，不同特征的情况
                    string strNum = "";
                    string strNumC = "";
                    string strKH = "";
                    string strKHC = "";
                    
                    for ( int i=0;i<listTEMPKHJS.Count;i++)
                    {
                        listT.Clear();
                        strKH = listTEMPKHJS[i];
                        listT.Add(strKH);
                        string[] str = find_str(@"[\(\（][^\(\)\（\）]+[\)\）]", strKH);
                        foreach(string strL in str)
                        {
                            strNum= Regex.Replace(strL, @"\(", "");
                            strNum = Regex.Replace(strNum, @"\（", "");
                            strNum = Regex.Replace(strNum, @"\)", "");
                            strNum = Regex.Replace(strNum, @"\）", "");
                            if (IsNumber(strNum))
                            {
                                
                                for (int j=i+1;j < listTEMPKHJS.Count; j++)
                                {
                                    strKHC = listTEMPKHJS[j];
                                    string[] strC = find_str(@"[\(\（][^\(\)\（\）]+[\)\）]", strKHC);
                                    foreach (string strKHL in strC)
                                    {
                                        strNumC = Regex.Replace(strKHL, @"\(", "");
                                        strNumC = Regex.Replace(strNumC, @"\（", "");
                                        strNumC = Regex.Replace(strNumC, @"\)", "");
                                        strNumC = Regex.Replace(strNumC, @"\）", "");
                                        if (IsNumber(strNumC))
                                        {
                                           // getFstr(strKHC, "（", "(");
                                            if (strNum == strNumC )
                                            {
                                                if (!listT.Contains(strKHC))
                                                {
                                                    listT.Add(strKHC);
                                                }
                                            }
                                        }
                                    }

                                 }
                            }
                        }
                        if (listT.Count > 1)
                        {
                           // getFindDOCM(ref wDoc, ref DRange, ref wRange, listT.ToArray(), stypeText + "：相同附图标记对应不同特征[" + string.Join(",", listT.ToArray()) + "]", "", "QL");
                            JYResult iJYResultN = new JYResult();
                            iJYResultN.rNum = wRange.Count;
                            iJYResultN.sText = stypeText + "：相同附图标记对应不同特征[" + string.Join(",", listT.ToArray()) + "]";
                            iJYResultN.sType = sType;
                            iJYResultN.sQStr = listT.ToArray();
                            iJYResultN.pRange = DRange;
                            wRange.Add(iJYResultN);
                        }
                    }

                    for (int i = 0; i < listTEMPJS.Count; i++)
                    {
                        listT.Clear();
                        strKH = listTEMPJS[i];
                        listT.Add(strKH);
                        string[] str = find_str(@"[0-9]+", strKH);
                        foreach (string strL in str)
                        {
                            if (IsNumber(strL))
                            {
                                
                                for (int j = i + 1; j < listTEMPJS.Count; j++)
                                {
                                    strKHC = listTEMPJS[j];
                                    string[] strC = find_str(@"[0-9]+", strKHC);
                                    foreach (string strKHL in strC)
                                    {
                                        if (IsNumber(strKHL))
                                        {
                                            if (strL == strKHL)
                                            {
                                                if (!listT.Contains(strKHC))
                                                {
                                                    listT.Add(strKHC);
                                                }
                                            }
                                        }
                                    }

                                }
                            }
                        }
                        if (listT.Count > 1)
                        {
                            //getFindDOCM(ref wDoc, ref DRange, ref wRange, listT.ToArray(), stypeText + "：相同附图标记对应不同特征[" + string.Join(",", listT.ToArray()) + "]", "", "QL");
                            JYResult iJYResultN = new JYResult();
                            iJYResultN.rNum = wRange.Count;
                            iJYResultN.sText = stypeText + "：相同附图标记对应不同特征[" + string.Join(",", listT.ToArray()) + "]";
                            iJYResultN.sType = sType;
                            iJYResultN.sQStr = listT.ToArray();
                            iJYResultN.pRange = DRange;
                            wRange.Add(iJYResultN);
                        }
                    }



                }


            }
        }


        private bool sFindQLYQ(int iCount, ref int qlNum, ref Word.Document wDoc, ref Word.Range DRange, ref ArrayList wRange, string stypeText, string sType)
        {
            string str1 = "";
            string strXH = "";
            string strHW = "";
            int sLen = 0;
            bool flagQJ = false;
            bool bReturn = false;
            //获取权利要求序号
            str1 = DRange.Paragraphs[qlNum].Range.Text;
            str1=Regex.Replace(str1, @"\r", "");
            str1 = str1.Trim();
            if (string.IsNullOrEmpty(str1))
            {
                if (iCount > (qlNum + 1))
                {
                    qlNum = qlNum + 1;
                    bReturn = sFindQLYQ(iCount, ref qlNum, ref wDoc, ref DRange, ref wRange, stypeText, sType);
                    return bReturn;

                }
                else
                {
                    bReturn = true;
                    return bReturn;
                }
            }

           

            if (str1.Length < 10)
            { sLen = str1.Length; }
            else
            { sLen = 10; }

            strXH = getQLYQXHDOCM(str1, ref flagQJ);//获取项号

            if (string.IsNullOrEmpty(strXH))
            {
                if (str1.Length > 1)//获取行结尾最后一位
                {
                    strHW = str1.Substring(str1.Length - 1, 1);
                }
                else
                {
                    strHW = str1;
                }
                //判断行尾是否为句号
                if (strHW.Equals("。") == false)
                {
                    
                    if (iCount > (qlNum + 1))
                    {
                        qlNum = qlNum + 1;
                        if(sFindQLYQ(iCount, ref qlNum, ref wDoc, ref DRange, ref wRange, stypeText, sType))
                        {
                            //qlNum = qlNum - 1;
                            bReturn = true;
                        }
                    }
                    else
                    {
                        JYResult iJYResult = new JYResult();
                        iJYResult.rNum = wRange.Count;
                        iJYResult.sText = stypeText + "：权项结束缺少(。)[" + str1.Substring(0, sLen - 1) + ".....]";
                        iJYResult.sType = sType;
                        iJYResult.pRange = DRange.Paragraphs[qlNum].Range;
                        wRange.Add(iJYResult);
                    }
                }
            }
            else
            {
                bReturn = true;
            }

            return bReturn;
        }

        /// <summary>
        /// 获取权利要求和说明书所在的页
        /// </summary>
        /// <param name="wDoc"></param>
        /// <param name="QLRange"></param>
        /// <param name="SMRange"></param>
        /// <returns></returns>
        private bool getQLSMPage(ref Word.Document wDoc,ref Word.Range QLRange,ref Word.Range SMRange, ref Word.Range SMFTRange, ref bool WHTable,ref string QLWTable,ref string SMWTable, ref string SMFTWTable)
        {
           //if (wDoc.Sections.First.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Count != 0)  // 是页码
            bool isHeader = false;
            string sHeaderText = "";
            string sHV = "";
            string wtable = "";
            WHTable = false;
            QLWTable = "";
            SMWTable = "";
            try
            {
                if (wDoc.Sections.First.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Exists)  // 判断有页眉
                {

                    if (wDoc.Sections.Count > 0)
                    {
                        wDoc.Activate();
                        Word.HeaderFooter ftr = wDoc.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
                        Word.Range ftrRange = ftr.Range;
                        Word.Paragraphs paras = ftrRange.Paragraphs;
                        for (int counter = 1; counter <= paras.Count; counter++)
                        {
                            Word.Paragraph para = paras[counter];
                            sHeaderText = para.Range.Text;
                            if (sHeaderText.IndexOf("2006.") >= 0)
                            {
                                sHV = "Table";
                                break;
                            }
                            else if (sHeaderText.IndexOf("2010.") >= 0)
                            {
                                sHV = "Header";
                                break;
                            }
                        }

                        if (sHV == "Header")
                        {
                            for (int j = 1; j <= wDoc.Sections.Count; j++)
                            {
                                sHeaderText = wDoc.Sections[j].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range.Text;

                                sHeaderText = sHeaderText.Replace(" ", "");
                                if (sHeaderText.IndexOf("权利要求书\r") >= 0)
                                {
                                    QLRange = wDoc.Sections[j].Range;
                                    isHeader = true;
                                }
                                else if (sHeaderText.IndexOf("说明书\r") >= 0)
                                {
                                    SMRange = wDoc.Sections[j].Range;
                                    isHeader = true;
                                }
                                else if (sHeaderText.IndexOf("说明书附图\r") >= 0)
                                {
                                    SMFTRange = wDoc.Sections[j].Range;
                                    isHeader = true;
                                }//
                            }
                        }
                        else if (sHV == "Table")
                        {
                            for (int k = 1; k <= wDoc.Sections.Count; k++)
                            {
                                if (wDoc.Sections[k].Range.Tables.Count > 0)
                                {
                                    Word.Table nowTable = wDoc.Sections[k].Range.Tables[1];
                                    // string ss = nowTable.Range.Text;
                                    for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
                                    {
                                        sHeaderText = nowTable.Cell(rowPos, 1).Range.Text;
                                        wtable = sHeaderText;
                                        sHeaderText = sHeaderText.Replace(" ", "");
                                        if (sHeaderText.IndexOf("权利要求书\r") >= 0)
                                        {
                                            QLRange = wDoc.Sections[k].Range;
                                            isHeader = true;
                                            WHTable = true;
                                            QLWTable = wtable;
                                        }
                                        else if (sHeaderText.IndexOf("说明书\r") >= 0)
                                        {
                                            SMRange = wDoc.Sections[k].Range;
                                            isHeader = true;
                                            WHTable = true;
                                            SMWTable = wtable;
                                        }
                                        else if (sHeaderText.IndexOf("说明书附图\r") >= 0)
                                        {
                                            SMFTRange = wDoc.Sections[k].Range;
                                            isHeader = true;
                                            WHTable = true;
                                            SMFTWTable = wtable;
                                        }

                                    }
                                }
                            }

                        }
                    }


                    //for (int j = 1; j <= wDoc.Sections.Count; j++)
                    //{
                    //    wDoc.Activate();
                    //   //sHeaderText=wDoc.Sections[j].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.Text;
                    //    Word.HeaderFooter ftr = wDoc.Sections[j].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
                    //    Word.Range ftrRange = ftr.Range;
                    //    Word.Paragraphs paras = ftrRange.Paragraphs;
                    //    for (int counter = 1; counter <= paras.Count; counter++)
                    //    {
                    //        Word.Paragraph para = paras[counter];
                    //        sHeaderText= para.Range.Text;
                    //        if (sHeaderText.IndexOf("权利要求书") >= 0)
                    //        {
                    //            QLRange = wDoc.Sections[j].Range;
                    //            isHeader = true;
                    //        }
                    //        else if (sHeaderText.IndexOf("说明书") >= 0)
                    //        {
                    //            SMRange = wDoc.Sections[j].Range;
                    //            isHeader = true;
                    //        }
                    //    }  
                    //}
                }
            }
            catch (Exception ex)
            {
                log.Error("获取权利要求和说明书所在的页出错!", ex);
                //throw new Exception("读取注册表出错!", ex);
            }

            return isHeader;
        }


        /// <summary>
        /// 获取office版本，支持
        /// </summary>
        /// <returns></returns>
        public int checkOffice()
        {
            int officeVersion = 0;
            RegistryKey rk = null;// Registry.LocalMachine;
            RegistryKey office2016 = null;
            RegistryKey office2013 = null;
            RegistryKey office2010 = null;
            RegistryKey office2003 = null;
            RegistryKey office2007 = null;
            RegistryKey office97 = null;
            RegistryKey office2000 = null;
            RegistryKey officexp = null;
            try
            {
                if (Environment.Is64BitOperatingSystem)
                {
                    rk = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                }
                else
                {
                    rk = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                }  

                office2016 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\16.0\\Word\\InstallRoot\\");//查询2016、2019
                office2013 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\15.0\\Word\\InstallRoot\\");
                office2010 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\14.0\\Word\\InstallRoot\\");
                //office 2003
                office2003 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");
                //office2007
                office2007 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");
                //office 97
                office97 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\8.0\\Word\\InstallRoot\\");
                //office 2000
                office2000 = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\9.0\\Word\\InstallRoot\\");
                //office xp
                officexp = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\10.0\\Word\\InstallRoot\\");

                //检查本机是否安装Officexp
                if (officexp != null)
                {
                    string office_xp = officexp.GetValue("Path").ToString();
                    if (File.Exists(office_xp + "Word.exe"))
                    {
                        officeVersion = 1998;
                    }
                }
                else
                {
                    officexp = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\10.0\\Word\\InstallRoot\\");
                    if (officexp != null)
                    {
                        string office_xp = officexp.GetValue("Path").ToString();
                        if (File.Exists(office_xp + "Word.exe"))
                        {
                            officeVersion = 1998;
                        }
                    }      
                }

                //检查本机是否安装Office97
                if (office97 != null)
                {
                    string office_97 = office97.GetValue("Path").ToString();
                    if (File.Exists(office_97 + "Word.exe"))
                    {
                        officeVersion = 1997;
                    }
                }
                else
                {
                    office97 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\8.0\\Word\\InstallRoot\\");
                    if (office97 != null)
                    {
                        string office_97 = office97.GetValue("Path").ToString();
                        if (File.Exists(office_97 + "Word.exe"))
                        {
                            officeVersion = 1997;
                        }
                    }
                       
                }
                //检查本机是否安装Office2000
                if (office2000 != null)
                {
                    string office_2000 = office2000.GetValue("Path").ToString();
                    if (File.Exists(office_2000 + "Word.exe"))
                    {
                        officeVersion = 2000;
                    }
                }
                else
                {
                    office2000 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\9.0\\Word\\InstallRoot\\");
                    if (office2000 != null)
                    {
                        string office_2000 = office2000.GetValue("Path").ToString();
                        if (File.Exists(office_2000 + "Word.exe"))
                        {
                            officeVersion = 2000;
                        }
                    }     
                }

                //检查本机是否安装Office2003
                if (office2003 != null)
                {
                    string office_2003 = office2003.GetValue("Path").ToString();
                    if (File.Exists(office_2003 + "Word.exe"))
                    {
                        officeVersion = 2003;
                    }
                }
                else
                {
                    office2003 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");
                    if (office2003 != null)
                    {
                        string office_2003 = office2003.GetValue("Path").ToString();
                        if (File.Exists(office_2003 + "Word.exe"))
                        {
                            officeVersion = 2003;
                        }
                    }   
                }


                //检查本机是否安装Office2007
                if (office2007 != null)
                {
                    string office_2007 = office2007.GetValue("Path").ToString();
                    if (File.Exists(office_2007 + "WINWORD.exe"))
                    {
                        officeVersion = 2007;
                    }
                }
                else
                {
                    office2007 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");
                    if (office2007 != null)
                    {
                        string office_2007 = office2007.GetValue("Path").ToString();
                        if (File.Exists(office_2007 + "WINWORD.exe"))
                        {
                            officeVersion = 2007;
                        }
                    } 
                }

                //检查本机是否安装Office2010
                if (office2010 != null)
                {
                    string office_2010 = office2010.GetValue("Path").ToString();
                    if (File.Exists(office_2010 + "WINWORD.exe"))
                    {
                        officeVersion = 2010;
                    }
                }
                else
                {
                    office2010 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\14.0\\Word\\InstallRoot\\");
                    if (office2010 != null)
                    {
                        string office_2010 = office2010.GetValue("Path").ToString();
                        if (File.Exists(office_2010 + "WINWORD.EXE"))
                        {
                            officeVersion = 2010;
                        }
                    }     
                }

                //检查本机是否安装Office2013
                if (office2013 != null)
                {
                    string office_2013 = office2013.GetValue("Path").ToString();
                    if (File.Exists(office_2013 + "WINWORD.EXE"))
                    {
                        officeVersion = 2013;
                    }

                }
                else
                {
                    office2013 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\15.0\\Word\\InstallRoot\\");
                    if (office2013 != null)
                    {
                        string office_2013 = office2013.GetValue("Path").ToString();
                        if (File.Exists(office_2013 + "WINWORD.EXE"))
                        {
                            officeVersion = 2013;
                        }
                    }    
                }

                //检查本机是否安装Office2016       
                if (office2016 != null)
                {
                    string office_2016 = office2016.GetValue("Path").ToString();
                    if (File.Exists(office_2016 + "WINWORD.EXE"))
                    {
                        officeVersion = 2016;
                    }
                }else
                {
                    office2016 = rk.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Office\\16.0\\Word\\InstallRoot\\");//查询2016、2019
                    if (office2016 != null)
                    {
                        string office_2016 = office2016.GetValue("Path").ToString();
                        if (File.Exists(office_2016 + "WINWORD.EXE"))
                        {
                            officeVersion = 2016;
                        }
                    }      
                }
            }
            catch (SecurityException ex)
            {
                log.Error("您没有读取注册表的权限", ex);
                //throw new System.Security.SecurityException("您没有读取注册表的权限", ex);
            }
            catch (Exception ex)
            {
                log.Error("读取注册表出错!", ex);
                //throw new Exception("读取注册表出错!", ex);
            }
            finally
            {
                if (rk != null)
                {
                    rk.Close();
                    rk = null;
                }
                if (office2016 != null)
                {
                    office2016.Close();
                    office2016 = null;
                }
                if (office2013 != null)
                {
                    office2013.Close();
                    office2013 = null;
                }
                if (office2010 != null)
                {
                    office2010.Close();
                    office2010 = null;
                }
                if (office2007 != null)
                {
                    office2007.Close();
                    office2007 = null;
                }
                if (office2003 != null)
                {
                    office2003.Close();
                    office2003 = null;
                }
                if (office2000 != null)
                {
                    office2000.Close();
                    office2000 = null;
                }
                if (office97 != null)
                {
                    office97.Close();
                    office97 = null;
                }
                if (officexp != null)
                {
                    officexp.Close();
                    officexp = null;
                }
            }
            return officeVersion;
        }

        public string getUnicodeList()
        {
            string sreturn = "";
            string s1 = "";
            string s2 = "";
            string s3 = "";
            string s4 = "";
            string[] su = { "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};

            for (int i=0;i< su.Length; i++)
            {
                s1="000" + su[i];
                sreturn = sreturn + ",'" + s1 + "'";
                for (int j = 1; j < su.Length; j++)
                {
                    s2 = s1.Substring(1) + su[j];
                    sreturn = sreturn + ",'" + s2 + "'";
                    for (int k = 1; k < su.Length; k++)
                    {
                        s3 = s2.Substring(1) + su[k];
                        sreturn = sreturn + ",'" + s3 + "'";
                        for (int h = 1; h < su.Length; h++)
                        {
                            s4 = s3.Substring(1) + su[h];
                            sreturn = sreturn + ",'" + s4 + "'";
                        }
                    }
                }
            }


            return sreturn;
        }



        /// <summary>
        /// 获取项号
        /// </summary>
        /// <param name="Dtext">权利要求文本</param>
        /// <param name="flagQJ">是否包含全角项号</param>
        /// <returns></returns>
        private string getQLYQXHDOCM(string Dtext,ref bool flagQJ)
        {
            string streturn = "";
            char[] szl = { '0','1','2','3','4','5','6','7','8','9',  };
            char[] szlQJ = { '０','１','２','３','４','５','６','７','８','９'};
            int i = 0, idx=0;
            flagQJ = false;//全角项号
            foreach(char L in Dtext)
            {
                if (i == 0)
                {
                    idx=Array.IndexOf(szl,L);
                    if (idx >= 0)
                    {
                        streturn = streturn + szl[idx].ToString();
                    }
                    else
                    {
                        idx = Array.IndexOf(szlQJ, L);
                        if (idx >= 0)
                        {
                            streturn = streturn + szl[idx].ToString();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
               
            }

            return streturn;
        }


        /// <summary>
        /// 获取第一次标记符出现位置前的字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="patternOld"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public string getFstr(string str, string patternOld,string pattern)
        {
            string sReturn = "";
            str=Regex.Replace(str, patternOld, pattern);
            int idf=str.IndexOf("pattern");
            if( idf > 0)
            {
                sReturn = str.Substring(0, idf - 1);
            }
            
            return sReturn;

        }

        /// <summary>
        /// 获取正则表达式中的符合条件的字符
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public int find_count(string pattern, string input)
        {
            Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            return regex.Matches(input).Count;
        }
        /// <summary>
        /// 获取正则表达式中的符合条件的字符个数
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public int find_count0(string pattern, string input)
        {
            string str = pattern;
            int startIndex = 0;
            while (startIndex < str.Length)
            {
                if (ismatch(@"[\*\.\?\+\$\[\]\(\)\{\}\|\\\/]", str.Substring(startIndex, 1)))
                {
                    str = str.Insert(startIndex, @"\");
                    startIndex += 2;
                }
                else
                {
                    startIndex++;
                }
            }
            Regex regex = new Regex(str, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            return regex.Matches(input).Count;
        }
        public  int[] find_pos(string pattern, string input)
        {
            List<int> list = new List<int>();
            MatchCollection matchs = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).Matches(input);
            foreach (Match match in matchs)
            {
                list.Add(match.Index);
            }
            return list.ToArray();
        }

        public bool ismatch(string pattern, string input)
        {
            Regex regex = new Regex(pattern);
            return regex.IsMatch(input);
        }

        public  int str_first(int input, int[] pos_input)
        {
            List<int> list = new List<int>(0);
            foreach (int num2 in pos_input)
            {
                if (num2 > input)
                {
                    list.Add(num2);
                    break;
                }
            }
            if (list.Count == 0)
            {
                list.Add(-1);
            }
            return list[0];
        }


        public string[] find_str(string pattern, string input)
        {
            List<string> list = new List<string>();
            MatchCollection matchs = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).Matches(input);
            foreach (Match match in matchs)
            {
                list.Add(match.Value);
            }
            return list.ToArray();
        }
        public void find_str(string pattern, string input,ref List<string> sFindA,ref List<int> lFindA)
        {
            //List<string> list = new List<string>();
            MatchCollection matchs = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).Matches(input);
            foreach (Match match in matchs)
            {
                sFindA.Add(match.Value);
                lFindA.Add(match.Index);
            }
          //  return list.ToArray();
        }

        public bool IsNumber(string str)
        {
            return Regex.IsMatch(str, @"^[0-9]\d*$");
        }

        /// <summary>
        /// 是否引用多项权利要求
        /// </summary>
        /// <param name="input">项号</param>
        /// <param name="str">权利要求内容</param>
        /// <returns></returns>
        public bool is_duoxiang(int input,ref int[] dxList, string str)
        {
            dxList = claim_yinyong(input, str);
            return (dxList.Length > 1);
        }

        public int[] claim_yinyong(int input, string str)
        {
            List<string> list2 = new List<string>();
            string str2 = str;
            if (str2.Contains("权利要求") && ismatch("[,，。]", str2))
            {
                int num4 = find_pos("权利要求", str2)[0];
                int num5 = str_first(num4, find_pos("[，,。]|所述", str2));
                if (num5 > num4)
                {
                    string item = Regex.Replace(str2.Substring(num4, num5 - num4), @"[\(（][^\(（\)）]+[\)）]", "");
                    list2.Add(item);
                }
            }
            if (!str2.Contains("权利要求") && ismatch("[，,。]", str2))
            {
                int num6 = find_pos("[，,。]", str2)[0];
                list2.Add("0");
            }
            List<int> source = new List<int>();
            if (ismatch(@"\d+[-至到～]\d+", list2[0]))
            {
                MatchCollection matchs = new Regex(@"(?<first>\d+)[-至到～](?<second>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase).Matches(list2[0]);
                foreach (Match match in matchs)
                {
                    GroupCollection groups = match.Groups;
                    int num7 = Convert.ToInt32(groups["first"].Value);
                    int num8 = Convert.ToInt32(groups["second"].Value);
                    for (int j = num7; j <= num8; j++)
                    {
                        source.Add(j);
                    }
                }
            }
            else if (ismatch(@"权利要求\d+[-至到～]权利要求\d+", list2[0]))
            {
                MatchCollection matchs2 = new Regex(@"权利要求(?<first>\d+)[-至到～]权利要求(?<second>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase).Matches(list2[0]);
                foreach (Match match2 in matchs2)
                {
                    GroupCollection groups2 = match2.Groups;
                    int num10 = Convert.ToInt32(groups2["first"].Value);
                    int num11 = Convert.ToInt32(groups2["second"].Value);
                    for (int k = num10; k <= num11; k++)
                    {
                        source.Add(k);
                    }
                }
            }
            if (ismatch("任|前述|上述|一项|多项", list2[0]) && !ismatch(@"\d+", list2[0]))
            {
                for (int m = 1; m < input; m++)
                {
                    source.Add(m);
                }
            }
            List<string> list4 = new List<string>();
            string[] strArray2 = find_str(@"\d+", list2[0]);
            if (strArray2.Length == 0)
            {
                source.Add(1);
            }
            else
            {
                foreach (string str8 in strArray2)
                {
                    int result = 1;
                    bool flag14 = int.TryParse(str8, out result);
                    source.Add(Convert.ToInt32(result));
                    if (!IsNumber(str8) && !list4.Contains(str8))
                    {
                        list4.Add(str8);
                    }
                }
            }
            return source.Distinct<int>().ToArray<int>();
        }


        /// <summary>
        /// 是否为独立权利要求
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public bool is_independent_claim(string str)
        {
            str=Regex.Replace(str, " ", "");
            str = Regex.Replace(str, "　", "");
            str = Regex.Replace(str, "、", ".");
            List<int> list = new List<int>();
            string str2 = str.Substring(1, str_first(1, find_pos("[，,。]", str)));
            if (find_pos("[，,。]", str).Length == 0)
            {
                str2 = str;
            }
            if (ismatch("按照|根据|如|依据", str2))
            {
                if (find_pos("一种", str2).Length > 0)
                {
                    if (ismatch("一种", str2) && (find_pos("一种", str2)[0] < 4))
                    {
                        list.Add(1);
                    }
                }
                else
                {
                    list.Add(0);
                }
                if (find_count(@"(?<=\.)按照|(?<=\.)根据|(?<=\.)如|(?<=\.)依据", str2) == 0)
                {
                    list.Add(1);
                }
                if ((find_count("用途", str2) > 0) && (find_count("所述用途|所述的用途|前述用途|前述的用途|该用途", str2) == 0))
                {
                    list.Add(1);
                }
            }
            else if (find_count(@"\d\.权利要求", str2) > 0)
            {
                list.Add(0);
            }
            else
            {
                list.Add(1);
            }
            if (list.Count == 0)
            {
                list.Add(0);
            }
            if (find_pos("方法，|方法。|方法,", str2).Length > 0) 
            {
                list.Add(1);
            }
            if (list.Contains(1))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 正则表达式替换字符串
        /// </summary>
        /// <param name="inputstring"></param>
        /// <param name="inputpattern"></param>
        /// <param name="inputreplacement"></param>
        /// <returns></returns>
        public string Regx_replaceall(string inputstring, string inputpattern, string inputreplacement)
        {
            string pattern = inputpattern;
            string replacement = inputreplacement;
            return Regex.Replace(inputstring, pattern, replacement);
            
        }

        public static string deletezifu(int pos, string inputstr)
        {
            string result;
            if (pos < inputstr.Length)
            {
                result = inputstr.Remove(pos, 1).Insert(pos, "*");
            }
            else
            {
                result = inputstr;
            }
            return result;
        }

        /// <summary>
        /// 获取权利要求特征
        /// </summary>
        /// <param name="wQLStr"></param>
        public ArrayList GetTeZheng( List<string> wQLStr)
        {
            string input = "";
            string useless_word = Properties.Resources.String_useless_word;
            string gudingdapei = Properties.Resources.String_gudingdapei;
            string userqdel = Properties.Resources.String_userqdel;
            
            gudingdapei = Regx_replaceall(gudingdapei, "\\*+", "([\\u4e00-\\u9fa5a-z\\d#]+)");
            List<string> xzList = new List<string>();
            List<string> ysList = new List<string>();
            // for (int i = 0; i <1;i++)// wQLStr.Count; i++)
            // {
            // input = wQLStr;
            // claimkuohao = wQLStr;
            for (int i = 0; i <wQLStr.Count; i++)
            {
                wQLStr[i] = Regx_replaceall(wQLStr[i], "[\\u0001]", "");
                wQLStr[i] = Regx_replaceall(wQLStr[i], "[\\r\\f]", "");
                wQLStr[i] = Regx_replaceall(wQLStr[i], "[,;，。；、：:\\-]", "*");
                wQLStr[i] = Regx_replaceall(wQLStr[i], "([\\(\\（][^\\(\\（]+[\\)\\）])", "#");
                wQLStr[i] = Regx_replaceall(wQLStr[i], "[^\\u4e00-\\u9fa5:,;\\.。；：]+[\\＝][^\\u4e00-\\u9fa5:,;\\.。；：]+", "");
                wQLStr[i] = Regx_replaceall(wQLStr[i], " ", "");
                xzList.Add(wQLStr[i]);
                ysList.Add(wQLStr[i]);
            }
            


            List<int> xinghaoweizhiList = new List<int>();
            string[] wuyongciStrings = useless_word.Split(new char[] { '|' });
           
            
          //  string inputbijiao = input;
            Parallel.ForEach<string>(wuyongciStrings, delegate (string m)
            {
                Regex regexguding2 = new Regex(m, RegexOptions.IgnoreCase | RegexOptions.Compiled);

                for(int j=0; j < ysList.Count; j++)
                {
                    MatchCollection matches2 = regexguding2.Matches(ysList[j]);
                    foreach (object obj in matches2)
                    {
                        Match m3 = (Match)obj;
                        string temp = m3.Value;
                        string s2 = new string('*', m3.Length);
                        //int[] x = find_pos(temp, input);
                        //int[] xinghaoweizhInts = find_pos("\\*", s2);
                        xzList[j] = xzList[j].Remove(m3.Index, m3.Length).Insert(m3.Index, s2);
                        //foreach (int m4 in xinghaoweizhInts)
                        //{
                        //    if (!xinghaoweizhiList.Contains(m4 + m3.Index))
                        //    {
                        //        xinghaoweizhiList.Add(m4 + m3.Index);
                        //        inputbijiao = deletezifu(m4 + m3.Index, inputbijiao);
                        //    }
                        //}
                    }
                }
                       
            });

                
            string path = Directory.GetCurrentDirectory();
            JiebaSegmenter segmenter = new JiebaSegmenter();
            segmenter.LoadUserDict(path + "\\Resources\\userdict.txt");
            PosSegmenter posSeg = new PosSegmenter();
            ArrayList fenciA = new ArrayList();

            foreach(string dok in xzList)
            {
                List<string> fencitiquciku = new List<string>();
                IEnumerable<Pair> tokens = posSeg.Cut(dok, true);

                string fencitemp = string.Join(" ", from token in tokens
                                                    select string.Format("{0}/{1}", token.Word, token.Flag));
                fencitemp = Regex.Replace(fencitemp, "[\\*#\\d]/x", "#");
                fencitemp = Regex.Replace(fencitemp, " ", "");
                fencitemp = Regex.Replace(fencitemp, "[^/#]+/d", "#");
                fencitemp = Regex.Replace(fencitemp, "[^/#]+/p", "#");
                fencitemp = Regex.Replace(fencitemp, "[^/#]+/f", "#");
                fencitemp = Regex.Replace(fencitemp, "[^/#]+/#", "#");
                fencitemp = Regex.Replace(fencitemp, "[^/#]+/vg", "#");

                string[] fencitemp2 = find_str("[^#\\n]+", fencitemp);
                Parallel.ForEach<string>(fencitemp2, delegate (string m)
                {
                    if (find_count("/n$|/vn$|/nz$|/x$", m) > 0)
                    {
                        string tempfenci = Regex.Replace(m, "/[a-z]{1,4}", "");
                        if (!fencitiquciku.Contains(tempfenci))
                        {
                            fencitiquciku.Add(tempfenci);
                        }
                    }
                });
                fenciA.Add(fencitiquciku);
            }


            string[] gudingdapeiSplit = gudingdapei.Split(new char[]{'|'});

            Parallel.ForEach<string>(gudingdapeiSplit, delegate (string m)
            {
                if (m.Length == 0)
                {
                    // MessageBox.Show("固定搭配词库有错误！");
                }
                else
                {
                    string[] x = find_str(m, input);
                    Regex regexguding2 = new Regex(m, RegexOptions.IgnoreCase | RegexOptions.Compiled);

                    for (int j = 0; j < ysList.Count; j++)
                    {

                        MatchCollection matches2 = regexguding2.Matches(ysList[j]);
                        foreach (object obj in matches2)
                        {
                            Match m3 = (Match)obj;
                            string temp = m3.Value;
                            temp = Regex.Replace(temp, m, "*$1*");
                            string[] xStr = find_str("[^\\*#]+", temp);

                            if (!(xStr.Length == 0))
                            {
                                int firstpos = m3.Value.IndexOf(xStr[0]);
                                string s2 = new string('*', firstpos);
                                string s3 = new string('*', m3.Length - firstpos - xStr[0].Length);
                                string temp2 = s2 + xStr[0] + s3;
                                string temp3 = input;
                                int[] xinghaoweizhInts = find_pos("\\*", temp2);

                                // xzList[j] = xzList[j].Remove(m3.Index, temp2.Length).Insert(m3.Index, temp2);
                                foreach (int m4 in xinghaoweizhInts)
                                {
                                    xzList[j] = deletezifu(m4 + m3.Index, xzList[j]);
                                    //if (!xinghaoweizhiList.Contains(m4 + m3.Index))
                                    //{
                                    //    xinghaoweizhiList.Add(m4 + m3.Index);
                                            
                                    //}
                                }
                            }
                        }

                    }

                }
            });

            //foreach (int j in xinghaoweizhiList.ToArray())
            //{
            //    input = deletezifu(j, input);
            //}
            ArrayList fenciB = new ArrayList();
            for (int i = 0; i < xzList.Count; i++)
            {
                string[] tezheng = find_str("[^\\*#\\n ]+", xzList[i]);
                ArrayList tezhengciku = new ArrayList();

                string Finaltezheng = string.Join("*", tezheng);
                Finaltezheng = Regex.Replace(Finaltezheng, "[ \u3000\\n]", "");
                Finaltezheng += "*";
                Finaltezheng = Regx_replaceall(Finaltezheng, "\\*[\\u4e00-\\u9fa5\\w]\\*", "**");
                string[] finalquchong = find_str("[^#\\*]+", Finaltezheng);
                List<string> quchongList = new List<string>();
                foreach (string j in finalquchong)
                {
                    if (!quchongList.Contains(j) && Regex.Replace(j, " ", "").Length > 1)
                    {
                        quchongList.Add(j);
                    }
                }
                fenciB.Add(quchongList);
            }

            //
            string[] wuyongci = useless_word.Split(new char[] { '|' });
            List<string> suoshu = new List<string>();
            suoshu.Add("所述的");
            suoshu.Add("前述的");
            suoshu.Add("上述的");
            suoshu.Add("该");
            suoshu.Add("所述");
            suoshu.Add("前述");
            suoshu.Add("上述");

            for (int i = 0; i < ysList.Count; i++)
            {
                string claimkh = Regex.Replace(ysList[i], "与|和", "#");

                foreach (string k in wuyongci)
                {
                    if (!suoshu.Contains(k))
                    {
                        claimkh = Regex.Replace(claimkh, k, "#");
                    }
                }

                string[] rawtezheng = find_str("所述[\\u4e00-\\u9fa5\\w]+[\\(\\（][\\d\\w\\-]+[\\)\\）]|上述[\\u4e00-\\u9fa5\\w]+[\\(\\（][\\d\\w\\-]+[\\)\\）]|该[\\u4e00-\\u9fa5\\w]+[\\(\\（][\\d\\w\\-]+[\\)\\）]|前述[\\u4e00-\\u9fa5\\w]+[\\(\\（][\\d\\w\\-]+[\\)\\）]", claimkh);
                foreach (string l in rawtezheng)
                {
                    string temptezheng = Regex.Replace(l, "[\\(\\（][\\d\\w\\-]+[\\)\\）]", "");
                    temptezheng = Regex.Replace(temptezheng, " ", "");
                    temptezheng = Regex.Replace(temptezheng, "所述的|前述的|上述的|上述|所述|前述|该|一种", "");
                    if (!((List<string>)fenciB[i]).Contains(temptezheng) && temptezheng.Length < 10)
                    {
                        ((List<string>)fenciB[i]).Add(temptezheng);
                    }
                }
            }

            
            for (int i = 0; i < fenciA.Count; i++) 
            {
                foreach (string m3 in ((List<string>)fenciA[i]))
                {
                    if (!((List<string>)fenciB[i]).Contains(m3))
                    {
                        ((List<string>)fenciB[i]).Add(m3);
                    }
                }
            }

            ////    Finaltezheng = string.Join("*", quchongList.ToArray());
            ////    Finaltezheng = Regex.Replace(Finaltezheng, "[\\r\\f]", "");
            ////wQLStr = Finaltezheng;

            ////}


            ////前词去除操作
            //string[] qiancidelStrings = userqdel.Split(new char[] { '|' });
            //for (int i = 0; i < fenciB.Count; i++)
            //{
            //    for(int j=0;j< ((List<string>)fenciB[i]).Count; j++)
            //    {
            //        string m=((List<string>)fenciB[i])[j];
            //        foreach(string qci in qiancidelStrings)
            //        {
            //            if (m.Equals(qci)==false && m.IndexOf(qci) == 0)
            //            {
            //                ((List<string>)fenciB[i])[j]=m.Substring(qci.Length - 1, m.Length - qci.Length);
            //            }
            //        }
            //    }
            //}

            return fenciB;

        }

    }
}
